package com.graduate.daydayup.room

import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase


@Database(
    entities = [Schedule::class,Account::class,NoteType::class,NoteContent::class],
    version = 1,
    exportSchema = false
)

abstract class MyRoomDataBase : RoomDatabase() {
    companion object {
        @Volatile
        private var instance: MyRoomDataBase? = null

        fun getInstance(context: Context): MyRoomDataBase {
            if (instance == null) {
                synchronized(MyRoomDataBase::class) {
                    if (instance == null) {
                        instance = Room.databaseBuilder(
                            context.applicationContext,
                            MyRoomDataBase::class.java,
                            "Flag"
                        )
                            .fallbackToDestructiveMigration()
                            .allowMainThreadQueries()
                            .build()
                    }
                }
            }
            return instance!!
        }
    }

    abstract fun scheduleDao(): ScheduleDao
    abstract fun accountDao(): AccountDao
    abstract fun noteTypeDao(): NoteTypeDao
    abstract fun noteContentDao(): NoteContentDao
}